cmake_minimum_required(VERSION 3.15)

# Find required packages
find_package(Threads REQUIRED)

# Test executables
set(TEST_SOURCES
    test_all_features.cpp
    test_batch_write.cpp
    test_endpoint_config.cpp
    test_minimal_demo.cpp
    test_query.cpp
    test_security.cpp
    test_single_write.cpp
    test_timeout.cpp
    test_timeout_validation.cpp
)

# Create executable for each test file
foreach(test_source ${TEST_SOURCES})
    # Get test name without extension
    string(REPLACE ".cpp" "" test_name ${test_source})

    # Create executable
    add_executable(${test_name} ${test_source})

    # Link with SDK and dependencies
    target_link_libraries(${test_name}
        PRIVATE
            kwdb_sdk
            ingest_proto
            Threads::Threads
    )

    # Include directories
    target_include_directories(${test_name} PRIVATE
        ${CMAKE_SOURCE_DIR}/sdk-cpp/include
        ${CMAKE_BINARY_DIR}/generated
    )

    # C++14 required
    target_compile_features(${test_name} PRIVATE cxx_std_14)
endforeach()

# Copy validation script to build directory
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/validate_all.sh
               ${CMAKE_CURRENT_BINARY_DIR}/validate_all.sh
               COPYONLY)